<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="./vue.js"></script>
</head>

<body>
  <div id="app">
    <div v-htx="'red'">孙小双</div>
    <div v-htx="'green'">李怡然</div>
    <div v-htx="'blue'">李娟娟</div>
    <div v-htx="mycolor">吉泽明步</div>

    <hr>
    
    <div v-htx2="mycolor">吉泽明步</div>
  </div>

  <script>
    Vue.directive('htx', {
      inserted(el, binding) {
        el.style.backgroundColor = binding.value
      },
      update(el, binding) {
        el.style.backgroundColor = binding.value
      }
    })
    // 或者
    Vue.directive('htx2', function(el, binding) {
      el.style.backgroundColor = binding.value
    })
    var vm = new Vue({
      el: '#app',
      data() {
        return {
          mycolor: '#dda223'
        }
      },

    })
  </script>
</body>

</html>